<?php

class Option_m extends CI_Model {
   
	function get_options(){
		// $this->db->where('enabled', 1);
		$this->db->order_by('key', 'asc');
		return
		$this->db->get('options')->result();
	}
	
	function get_option($id){
		return $this->db->where('id', $id)->get('options')->row();
	}
	
	function get_option_by_key($key){
		return $this->db->where('key', $key)->get('options')->row();
	}
	
	function save($data){
		if($data['id']){
			$this->db->where('id', $data['id']);
			$this->db->update('options', $data);
			return $data['id'];
		}else{
			$this->db->insert('options', $data);
			return $this->db->insert_id();
		}
	}
	
	function delete_option($id){
		//delete the option
		$this->db->where('id', $id);
		$this->db->delete('options');
	}
}
